import pygame,sys,os

class Spike(pygame.sprite.Sprite):
    def __init__(self,tl_x,tl_y,dire,speed):
        super().__init__()
        self.image = pygame.image.load(self.resource_path('source/img/one_spike.png'))
        self.rect = self.image.get_rect()
        self.rect.topleft = (tl_x,tl_y)
        self.dire = dire
        self.speed = speed

    def spike_move(self):
        if self.dire=='x':
            self.rect.x += self.speed
            if self.rect.x >= 1000:
                self.rect.x = 0
        else:
            self.rect.y += self.speed
            if self.rect.y >= 800:
                self.rect.y = 0
    def resource_path(self,relative_path):
        """ 根据打包后的环境动态加载资源路径 """
        if hasattr(sys, '_MEIPASS'):
            base_path = sys._MEIPASS
        else:
            base_path = os.path.abspath(".")
        return os.path.join(base_path, relative_path)